//
//  LGPatientSignHistoryCell.m
//  HeartDisease_YHJK
//
//  Created by 1234 on 2025/8/12.
//

#import "LGPatientSignHistoryCell.h"

@interface LGPatientSignHistoryCell()
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**  有效期 */
@property (nonatomic , strong)UIButton *iconBtn;
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)NSDictionary *statusDic;

@end

@implementation LGPatientSignHistoryCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.statusDic = @{@"0":@{@"title":@"进行中",@"color":@"#5E8EF5"},
                           @"1":@{@"title":@"未生效",@"color":@"#333333"},
                           @"2":@{@"title":@"已到期",@"color":@"#999999"}};
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.nameLabel.text = LGNSString(dataDic[@"title"]);
    self.timeLabel.text = [NSString stringWithFormat:@"%@ 至 %@",dataDic[@"vip_date_start"],dataDic[@"vip_date_end"]];
    NSString *status = LGNSString(dataDic[@"vipstatus"]);
    NSDictionary *statusDic = self.statusDic[status];
    self.statusLabel.text = statusDic[@"title"];
    self.statusLabel.textColor = [UIColor colorWithString:statusDic[@"color"]];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.iconBtn];
    [self.baseView addSubview:self.timeLabel];

    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.baseView).offset(viewPix(12));
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.nameLabel);
    }];
  
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(42));
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(0.5));
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(viewPix(12));
        make.width.equalTo(@(viewPix(65)));
        make.left.equalTo(self.nameLabel);
        make.height.equalTo(@(viewPix(20)));
        make.bottom.equalTo(self.baseView).offset(-viewPix(12));
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconBtn.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.iconBtn);
    }];
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#909399" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _statusLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E0E0E0"];
    }
    return _lineView;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UIButton *)iconBtn{
    if(!_iconBtn){
        _iconBtn = [UIButton buttonWithTitle:@" 有效期" titleFont:LGFont(14) textColor:@"#666666" imageName:@"患者资料-签约历史"];
        _iconBtn.bounds = CGRectMake(0, 0, viewPix(65), viewPix(20));
        _iconBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _iconBtn.userInteractionEnabled = NO;
    }
    return _iconBtn;
}


@end
